// pages/search/search.js
const app = getApp()

Page({
  data: {
    tabs: ['去旅行', '去海洋', '去太空', '去农场', '去森林'],
    imgs: [
      'http://delice.riki.cn/mavista/img/disclosure1.jpg',
      'http://delice.riki.cn/mavista/img/disclosure2.jpg',
      'http://delice.riki.cn/mavista/img/disclosure3.jpg',
      'http://delice.riki.cn/mavista/img/disclosure4.jpg',
      'http://delice.riki.cn/mavista/img/disclosure5.jpg'
    ],
    tabIndex: 0,
    imgH:2614
  },

  onLoad: function () {
    let _this = this;
    wx.getSystemInfo({
      success: function (res) {
        _this.setData({
          screenWidth: res.screenWidth
        })
      },
      
    })
    // wx.getImageInfo({
    //     src:_this.data.imgs[0],
    //     success(res){
    //       // console.log(res)
    //       _this.setData({
    //         imgH:res.height
    //       })
    //     }
    // })
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  onShow: function () {

  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  btnHit(e) {
    let tabIndex = e.currentTarget.dataset.index;
    let _this = this;
    var animation1 = wx.createAnimation({
      duration: 1000,
      timingFunction: 'ease'
    })
    var animation2 = wx.createAnimation({
      duration: 1000,
      timingFunction: 'ease'
    })
    var animation3 = wx.createAnimation({
      duration: 1000,
      timingFunction: 'ease'
    })
    var animation4 = wx.createAnimation({
      duration: 1000,
      timingFunction: 'ease'
    })
    var animation5 = wx.createAnimation({
      duration: 1000,
      timingFunction: 'ease'
    })
    var animation0 = wx.createAnimation({
      duration: 1000,
      timingFunction: 'ease'
    })
    let trX1 = _this.data.screenWidth / 5;
    let trX2 = _this.data.screenWidth * 2 / 5;
    let trX3 = _this.data.screenWidth * 3 / 5;
    let trX4 = _this.data.screenWidth * 4 / 5;
    let trX5 = _this.data.screenWidth;

    animation1.translateX(trX2).step({ duration: 500 });
    animation2.translateX(trX3).step({ duration: 500 });
    animation3.translateX(trX4).step({ duration: 500 });
    animation4.translateX(trX5).step({ duration: 500 });
    animation0.translateX(0).step({ duration: 500 });
    // console.log(tabIndex)
    if (tabIndex == 0) {
      _this.setData({
        tabIndex: tabIndex,
        animationData: animation0.export()
      })
    } else if (tabIndex == 0) {
      _this.setData({
        tabIndex: tabIndex,
        animationData: animation1.export()
      })
    } else if (tabIndex == 1) {
      _this.setData({
        tabIndex: tabIndex,
        animationData: animation2.export()
      })
    } else if (tabIndex == 2) {
      _this.setData({
        tabIndex: tabIndex,
        animationData: animation3.export()
      })
    } else if (tabIndex == 3) {
      _this.setData({
        tabIndex: tabIndex,
        animationData: animation4.export()
      })
    } else if (tabIndex == 4) {
      _this.setData({
        tabIndex: tabIndex,
        animationData: animation5.export()
      })
    }

  },
  swiperChange(e){
    // console.log(e)
    this.setData({
      tabIndex: e.detail.current
    })
  },
  order(e){
    let authCode = { 'authCode': wx.getStorageSync('authCode') };
    app.requestData('/api/purchase/order/contain_unpaid', authCode, 'GET', function (success) {
      console.log(success)
 
        wx.navigateTo({
          url: 'product/product',
        })
      
    })
  }
})



